<?php

namespace common\models;

/**
 * This is the model class for table "ArticleTag".
 */
class ArticleTag extends ActiveRecord {

    // only define rules for those attributes that
    // will receive user inputs.
    public function rules()
    {
        return [
            [['article_id', 'tag_id'], 'required'],
            [['article_id', 'tag_id'], 'integer'],
        ];
    }
    /**
     * @name 字段名称
     * @return array
     */
    public function attributeLabels()
    {
        return [
            'article_id' => '文章编号',
            'tag_id' => '标签编号',
        ];
    }
    
    /**
     * get tags
     */
    public function getTag()
    {
        return $this->hasOne(Tag::className(), ['id' => 'tag_id']);
    }

    /**
     * get article
     */
    public function getArticle()
    {
        return $this->hasOne(Article::className(), ['id' => 'article_id']);
    }

    // @name 保存标签串、相关配置等
    // @param $patternId int 文章编号
    // @param $tags string 标签串
    // @return boolean
    public static function updateTags($articleId, $tags)
    {
        return Tag::updateRelateTags($articleId, $tags, new ArticleTag());
    }
}
